﻿using System;
using System.Diagnostics;
using RaytracerLib.MathLib;
using RaytracerLib.RenderableObjects;

namespace RaytracerLib.Rays
{
    public abstract class Ray
    {
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private Vector3 m_dir;

        public int Depth { get; protected set; }
        public Vector3 Start { get; protected set; }
        public RaySurfaceSide RaySurfaceSide { get; protected set; }

        protected Ray(Scene a_scene)
        {
            a_scene.Statistics.RaysCreated++;
        }

        public Vector3 Dir
        {
            get
            {
                return m_dir;
            }
            protected set
            {
                Debug.Assert(value.IsNormalized);
                m_dir = value;
            }
        }

        public Vector3 HitPoint(double a_distance)
        {
            return Start + Dir * a_distance;
        }

        public override string ToString()
        {
            return String.Format("{3}, Start: {0}; Dir: {1}; Depth: {2}, Type: {4}",
                Start, Dir, Depth, GetType().Name, RaySurfaceSide);
        }
    }
}